<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>


<%@page import="org.displaytag.util.ParamEncoder"%>
<%@page import="org.displaytag.tags.TableTagParameters"%>
<%@page import="java.util.List"%>

<%@page import="pl.un4giv3n.mightvsmagic.entity.Clan"%>
<%@page import="pl.un4giv3n.mightvsmagic.utils.ClanStatsUtil"%>
<tiles:insertTemplate template="menu.jsp">
	<tiles:putAttribute name="body">
		<div>
			<s:form action="rankingPage">
				<s:select label="Typ" list="#{'USER':'Użytkownicy', 'CLAN':'Klany'}" name="rankType"/>
				<s:submit value="Pokaż"/>
			</s:form>
			<%
				   String sortBy = request.getParameter((new ParamEncoder("clanListTable")).encodeParameterName(TableTagParameters.PARAMETER_SORT));
				   String sortOrder = request.getParameter(new ParamEncoder("clanListTable").encodeParameterName(TableTagParameters.PARAMETER_ORDER));
				   if(sortBy != null){
					   ClanStatsUtil.sort((List<Clan>)request.getAttribute("clanList"),sortBy, sortOrder);
				   }
			%>
			<display:table sort="external" id="clanListTable" name="clanList" requestURI="rankingPage.action" pagesize="50" class="rankingtable" decorator="pl.un4giv3n.mightvsmagic.utils.display.DisplayClanRankDecorator">
				  <display:column title="Lp." property="index"/>
				  <display:column property="name" sortable="true" sortName="name" title="Klan" href="showOtherClanPage.action" paramId="clanId" paramProperty="id"/>
				  <display:column property="memberCount" sortable="true" sortName="memberCount" title="Ilość członków"/>
				  <display:column property="fightsWon" sortable="true" sortName="fightsWon" title="Wygrane walki"/>
				  <display:column property="fightsLost" sortable="true" sortName="fightsLost" title="Przegrane walki"/>
				  <display:column property="goldWon" sortable="true" sortName="goldWon" title="Zdobyte złoto"/>
				  <display:column property="goldLost" sortable="true" sortName="goldLost" title="Stracone złoto"/>
				  <display:column property="warsWon" sortable="true" sortName="warsWon" title="Wygrane wojny"/>
				  <display:column property="warsLost" sortable="true" sortName="warsLost" title="Przegrane wojny"/>
			</display:table>
		</div>
	</tiles:putAttribute>
</tiles:insertTemplate>